Session has been expired. Please
login again
.
Home
Interview
Data Science
AI/ML
Cloud
Web Development
Java
.NET
Database
Scripting Language
Computer Basics
Basic Languages
QA Testing
Certifications
Mobile Development
Compliances
Engineering
Integration Platforms
Management
Security & Privacy
Servers
More ...
Online Test
India Entrance Exams
Data Science
Java
Certifications
.NET
Database
Computer Basics
GK
Testing
Basic Language
Engineering
Management
More ...
Tutorial
Python Tutorial
Java OOPs Concepts Tutorial
Java Collections Tutorial
Java String Handling Tutorial
Java Streaming API Tutorial
Java Exception Handling Tutorial
Java Multithreading Tutorial
Java Concurrency Tutorial
Java IO Package Tutorial
Difference Between
Trending Topics
LIVE Mock Interviews
Sign Up
Login
Prepare Interview
Trending
41
C#
60
Microsoft .NET
30
Machine Learning
20
ChatGPT
142
C++
49
Data Structures
62
Computer Basics
106
Python
73
DBMS
152
SQL
306
Core Java
15
Java Design Patterns
41
JPA
52
Hibernate
50
Spring Boot
30
Kotlin
52
iOS
14
Android
38
Apache Kafka
80
Language in C
52
REST API
49
HR Questions
75
SDLC
40
Cryptography
40
Selenium
50
Angular
27
PHP
27
HTML
40
React
.NET
82
ASP
41
C#
20
LINQ
31
ASP .NET
60
Microsoft .NET
AIML
47
Artificial Intelligence (AI)
30
Machine Learning
20
ChatGPT
30
NLP
36
OpenCV
30
TensorFlow
Basic Language
30
R Language
50
COBOL
20
Python Coding
48
Scala
49
Swift
30
Golang
30
Embedded C
142
C++
30
VBA
Certification
40
CCNA
Cloud
30
Snowflake
23
Oracle APEX
87
AWS
35
Microsoft Azure
30
Azure Data Factory
30
OpenStack
30
ServiceNow
Compliance
20
CCPA
30
GDPR
20
HITRUST
20
LGPD
20
PDPA
20
OSHA
20
HIPPA
20
PHIPA
20
FERPA
30
DPDP
20
PIPEDA
Computer Basics
50
MS Word
22
Operating System
30
Tips and Tricks
50
PoowerPoint
49
Data Structures
37
Microsoft Excel
65
Computer Networking
62
Computer Basics
50
Computer Science
Data Science
48
Python Pandas
30
Python Matplotlib
50
Django
30
Pandas
29
Deep Learning
40
Flask
30
PySpark
25
PyTorch
23
Data Science
30
SciPy
30
Generative AI
30
NumPy
106
Python
Database
34
Oracle
27
MongoDB
46
Entity Framework
46
AWS DynamoDB
20
Redis Cache
108
MySQL
30
Data Modeling
73
DBMS
40
MariaDB
30
Apache Hive
30
SSIS
30
PostgreSQL
53
SQLite
70
SQL Query
20
Teradata
25
Cassandra
44
Neo4j
50
MSSQL
46
OrientDB
152
SQL
20
Data Warehouse
40
IBM DB2
30
Data Mining
61
Elasticsearch
Engineering
25
MATLAB
30
VLSI
38
Digital Electronics
27
Software Engineering
30
Civil Engineering
29
Electrical Machines
30
Data Engineer
30
AutoCAD
28
Robotics
28
Power System
30
Electrical Engineering
30
Verilog
Integration
30
TIBCO
48
Informatica
29
Oracle CXUnity
10
Web Services
30
Salesforce Lightning
30
IBM Integration Bus
24
Power BI
30
OIC
30
Dell Boomi
31
Web API
34
Talend
57
Salesforce
20
IBM DataStage
Java
16
Java 15
30
Java Multithreading
26
Apache Wicket
306
Core Java
35
Log4j
14
JBoss
27
Java Mail
29
Java Applet
8
Google Gson
21
Java 21
20
Apache Camel
30
Java Support
84
Struts
31
RMI
18
JAXB
30
Java OOPs
9
Apache Tapestry
49
JSP
30
Java Concurrency
25
J2EE
24
JUnit
24
Java 11
27
JDBC
30
Java Garbage Collection
15
Java Design Patterns
53
Spring Framework
27
Java Swing
41
JPA
30
Java 8
52
Hibernate
64
JMS
24
JSF
20
Java 17
30
Java Exception Handling
50
Spring Boot
30
Kotlin
34
Servlets
80
EJB
57
Java Beans
Management
30
Pega
25
ITIL
30
Finance
30
SAP MM
30
JIRA
24
SAP ABAP
30
SCCM
30
Tally
Mobile Development
52
iOS
32
Ionic
14
Android
20
Mobile Computing
31
Xamarin
More
30
Accounting
40
Business Analyst
30
SSB
45
DevOps
50
Algorithm
30
Splunk
30
OSPF
30
Sqoop
16
JSON
30
Insurance
30
Scrum Master
30
Accounts Payable
30
IoT
25
Computer Graphics
32
GraphQL
30
Active Directory
25
XML
30
Bitcoin
30
Laravel
38
Apache Kafka
30
Kubernetes
30
Microservices
50
Adobe AEM
20
Tableau
30
PHP OOPs
30
Desktop Support
20
Fashion Designer
56
IAS
30
OOPs
28
SharePoint
30
Yoga Teachers Training
40
Nursing
30
Dynamic Programming
15
Linked List
30
CICS
25
School Teachers
29
Behavioral
80
Language in C
24
Apache Spark
60
Full-Stack Developer
40
Digital Marketing
30
Statistics
30
IIS
30
System Design
30
VISA
48
BPO
51
SEO
42
Cloud Computing
30
Google Analytics
10
ANT
24
SAS
52
REST API
49
HR Questions
28
Control System
30
Agile Methodology
30
Content Writer
20
Checkpoint
40
Hadoop
20
Banking
30
Technical Support
29
Blockchain
20
Mainframe
20
Nature
30
Docker
30
Sales
50
Chemistry
75
SDLC
26
RPA
40
Cryptography
30
College Teachers
30
Interview Tips
20
Blue Prism
28
Memcached
30
GIT
Scripting Language
20
JCL
59
JavaScript
58
Ajax
30
Express.js
30
Ansible
30
ES6
24
Electron.js
30
NodeJS
29
RxJS
50
ExtJS
30
Vue.js
22
jQuery
30
Svelte.js
50
Shell Scripting
30
Next.js
25
Knockout JS
38
TypeScript
27
PowerShell
30
Terraform
Security and Privacy
40
Ethical Hacking
50
Cyber Security
30
PII
20
Data Protection Act
30
BGP
Servers
16
Tomcat
8
Glassfish
30
Ubuntu
43
Linux
30
Weblogic
105
Unix
Testing
30
Cucumber
44
QTP
38
TestNG
30
Postman
30
SDET
29
Kali Linux
38
UiPath
40
Selenium
56
Quality Assurance
30
Mobile Testing
30
API Testing
30
Appium
20
ETL Testing
Web Development
74
Ruby On Rails
74
CSS
50
Angular
30
Yii
54
Oracle JET(OJET)
27
PHP
30
Frontend Developer
24
Zend Framework
26
RichFaces
25
Flutter
27
HTML
26
React Native
40
React
30
CakePHP
21
Angular JS
32
Angular 8
50
Web Developer
23
Dojo
30
Symfony
27
GWT
Ask Question
Mock Exams
Trending
42
C#.NET
50
Language in C
17
CSS
30
PHP
30
C++
30
HTML5
40
HTML
75
AWS Cloud Certification
66
SCWCD / OCWCD
35
Azure Cloud Certification
82
OCJP / SCJP
16
Google Cloud/GCP Certification
30
CCNA
38
Computer basics
20
Microsoft Word
19
Computer Organization
44
Microsoft Excel
20
Data Structures
20
Python
61
DBMS
25
SQL
71
Engineering Entrance
54
General Knowledge / GK
26
Food Quiz
67
Aptitude
74
Medical Entrance
71
Bank PO
114
India Law Entrance
72
Railway Recruitment
33
Hibernate
241
Core Java
15
Artificial Intelligence
35
CAT
80
Nursing
37
Android
20
COVID-19
15
JavaScript
.NET
67
VB.Net
50
ASP.Net
12
Microsoft .NET
42
C#.NET
AIML
113
Machine Learning
Basic Language
151
Swift
94
ABAP
92
COBOL Script
17
XML
50
Language in C
10
Perl
281
ZPL
17
CSS
136
Ruby on Rails
92
Go Language
142
R Language
96
A+ Language
81
Fortran
96
DLANG
88
F#
153
Kotlin
30
PHP
30
C++
226
MATLAB
73
Rust
30
HTML5
94
COBOL
76
Halide Language
132
VLang
102
X++ Language
40
HTML
Certification
75
AWS Cloud Certification
66
SCWCD / OCWCD
35
Azure Cloud Certification
82
OCJP / SCJP
16
Google Cloud/GCP Certification
30
CCNA
Cloud
62
Snowflake
118
Microsoft Azure SQL Database
49
Google Cloud BigQuery
Computer Basics
82
Information Technology
98
Computer Architecture
14
DOS
35
Computer Networking
38
Computer basics
73
Computer Science
20
Microsoft Word
23
Microsoft PowerPoint
19
Computer Organization
25
Computer Hardware
12
UNIX
10
Window 2003 Server
44
Microsoft Excel
20
Data Structures
61
Operating Systems
25
Operating System
14
Linux
Data Science
20
Django
147
Data Science
150
Posit
64
Power BI
20
Python
Database
91
Teradata
19
Microsoft Access
40
Oracle SQL Developer
230
MariaDB
11
Data Warehousing
93
Applications Manager Database
39
MySQL
88
Database Management
53
Amazon RDS
124
MongoDB
58
IBM Db2
77
Neo4j
15
Microsoft SQL Server
110
OrientDB
30
ORACLE
81
CouchDB
129
FileMaker
225
ADABAS
61
DBMS
65
SQLite
25
SQL
215
PostgreSQL
205
Informix
11
Database Administration
198
Redis
Engineering
74
Robotics
30
Electrical Engineering
174
Nanotechnology
12
Digital Electronics
83
Aerospace Engineering
71
Engineering Entrance
83
Industrial Engineering
106
Digital Signal Processing
46
Renewable Energy Engineering
159
Mechanical Engineering
68
Chemical Engineering
115
Software Engineering
72
Network Engineering
16
Electronics Engineering
114
Control Systems Engineering
92
Telecommunications Engineering
15
System Analysis
74
Civil Engineering
129
Biomedical Engineering
GK
18
Ramayana The Mythology
26
Hollywood Movies Quiz
120
General QA
31
IPL
54
General Knowledge / GK
50
Badminton
30
Geometry
19
General Science
26
Sports
19
Mahabharata Mythology
30
Politics Quiz
27
Football / Soccer
20
Trigonometry
20
Nature
15
Famous Personalities
12
Days And Years
26
Food Quiz
61
Bollywood Movies Quiz
18
National Geographic
19
American Football
12
World Geography
15
Physics
67
Aptitude
India Entrance Exams
74
Medical Entrance
78
SSC CGL
119
UPCET
97
SSC CPO
125
KCET
88
Banking Exams
169
PTU Exam
129
AP EAMCET
92
Defence Exams
103
VITEEE
84
JEE Main
212
WBJEE
95
IAS
378
NIFT
112
AIIMS
67
JEECUP Entrance exam
156
JEE Advanced
97
CDS Exam
20
JEE
114
TNEA
190
OJEE
82
IBPS PO
82
BCECE
73
Indian Economic Service Examin
77
NEET PG
92
Entrance Exams
85
CMC Vellore
172
COMEDK UGET
93
LAWCET Entrance Exam
68
CEED
110
RRB Exams
137
CUET
55
Engineering Entrance Exam
66
AIPVT Entrance Exam
117
SSC CHSL
160
AFMC
89
NEET
110
SSC
146
XAT
71
Bank PO
147
GCET
114
India Law Entrance
132
ACEE
80
IBPS Clerk
145
CG PET
87
RRB ALP
108
TS EAMCET
149
KEAM
70
NDA Entrance
103
MHT CET
140
SBI PO
134
AILET
152
IPU CET
122
RBI Assistant
100
Indian Economic Service Examin
148
CLAT
186
NID NEED
65
GATE
94
UPSC
87
SRMJEEE
72
Railway Recruitment
120
CA (Chartered Accountant)
225
HPCET
Java
35
Servlets
33
Hibernate
39
Spring Boot
23
J2EE
23
Java Swing
241
Core Java
28
J2ME
30
EJB
42
Java 8
39
JSP
39
Struts
10
JMS
32
JDBC
Management
20
System Analysis(SDLC)
20
Human Resource
15
Artificial Intelligence
35
CAT
30
PMP
Mobile Development
38
React Native
More
20
Easy Mathematics
50
Bootstrap
10
Analogous Pair
87
Unity
95
SignalR
27
PEGA
102
NEET
80
Nursing
10
Sentence Ordering
15
Word Series
50
DevOps
23
Good Clinical Practice (GCP)
37
Android
100
CLAT
101
GATE
16
English Vocabulary
10
Word Ordering
37
Medical Surgery
181
DIGITAL Command Language
132
BITSAT
20
COVID-19
Personality Development
35
Yoga Teachers Training
30
Yoga Teachers Training Level 3
30
Yoga Teachers Training Level 1
30
Yoga Teachers Training Level 2
Scripting Language
144
DLANG Shell
92
ECMAScript
58
Node.js
14
jQuery
26
Ajax
15
JavaScript
40
AngularJS
261
C shell
Security and Privacy
81
Cybersecurity
Testing
25
Software Testing
10
QTP
Web Development
282
Web Development
75
Vue.js
121
ReactJS
141
CodeIgniter
62
Flask
156
Laravel
78
Express.js
43
NextJS
Make Homepage
Bookmark this page
Subscribe Email Address
Top 150 Core Java Online Practice Test | Multiple Choice
Top 150 Core Java Online Practice Test | Multiple Choice
1.
Java
is case _
Sensitive
Insensitive
2. What a
Java programmer calls
a __ , a
C
/
C++
programmer calls a function?
Method
Object
3. enum is a Keyword in Java, introduced from
J2SE 5
TRUE
FALSE
4. The Separator [ ] is Used to declare array types
TRUE
FALSE
5. Can there be an
abstract class
with
no abstract methods
in it?
Yes
No
6. Can an
Interface
have an
inner class
?
Yes
No
7. Which of the following would compile without error?
int a = Math.abs(-5);
int b = Math.abs(5.0);
int c = Math.abs(5.5F);
int d = Math.abs(5L);
8. Which of the following are valid calls to
Math
.max?
Math.max(1,4)
Math.max(2.3, 5)
Math.max(1, 3, 5, 7)
Math.max(-1.5, -2.8f)
1, 2 and 4
2, 3 and 4
1, 2 and 3
2, 3 and 4
9. Which interface does java.util.HashTable implement?
Java.util.Map
Java.util.List
Java.util.HashTable
Java.util.Collection
10. Which interface provides the capability to store objects using a key-value pair?
Java.util.Map
Java.util.Set
Java.util.List
Java.util.Collection
11. Which is valid declaration of a float?
float f = 1F;
float f = 1.0;
float f = "1";
float f = 1.0d;
12. Which of the following are Java reserved words?
1) run
2) import
3) default
4) implement
2 and 3
2 and 4
3 and 4
1 and 2
13. Which of the following will directly stop the execution of a Thread?
wait()
notify()
notifyall()
exits synchronized code
14. Which will contain the body of the thread?
run();
stop();
start();
main();
15. Assume the following method is properly synchronized and called from a thread A on an object B:
wait(2000);
After calling this method, when will the thread A become a candidate to get another turn at the CPU?
After thread A is notified, or after two seconds.
After the lock on B is released, or after two seconds.
Two seconds after lock B is released.
Two seconds after thread A is notified.
16. Which of the following will not directly cause a thread to stop?
notify()
wait()
sleep()
InputStream access
17. Which class or interface defines the wait(), notify(),and notifyAll() methods?
Object
Runnable
Class
Thread
18. Which is a valid keyword in java?
interface
Float
string
unsigned
19. Which is the valid declarations within an interface definition?
public double method();
public final double method();
static void method(double d1);
protected void method(double d1);
20. Which is a valid declarations of a String?
String s = null;
String s = 'null';
String s = (String) 'ufeed';
String s = (String) 'abc';
21. Given:
class Super {
public float getNum( ) {
return 3.0f;
}
}
public class Sub extends Super {
}
Which method, placed after 'public class Sub extends Super {', causes compilation to fail?
public void getNum( ) { }
public void getNum(double d) { }
public float getNum( ) { return 4.0f; }
public double getNum(float d) { return 4.0d; }
22. Which one allow the class Thing to be instantiated using new Thing( )?
public class Thing { }
public class Thing { public Thing(void) {} }
public class Thing { public Thing(String s) {} }
23. Given:
public class ArrayTest {
public static void main(String[ ] args){
float f1[ ]=f[ ];
f1 = new float[10];
f = f1;
System.out.println("f[0] = " + f[0]);
}
}
What is the result?
It prints f2[0] = 0.0
It prints f2[0] = NaN
An error at 'f2 = f1;' causes compile to fail.
An error at 'System.out.println("f2[0] = " + f2[0]);' causes compile to fail.
24. Which one cause a compiler error?
float[ ] f = new float(3);
float f3[ ] = new float[3];
float[ ]f1 = new float[3];
25. After the following code fragment, what is the value in a?
String s;
int a;
s = "Foolish boy.";
a = s.indexOf("fool");
-1
0
4
random value
26. Given the following statement:
wb.setDouble(8.0*32.2+1.0);
What must be the data type of wb?
DoubleField
TextField
IntField
double
27. A compound statement is:
A collection of one or more statements enclosed in
braces
A statement involving if and else
A way of declaring variables
a way of setting the value of a variable
28. The data type for numbers such as 3.14159 is:
double
int
real
String
29. A function is:
An entity that receives inputs and outputs
A way of storing values
A sequence of characters enclosed by quotes
A kind of computer
30. What will be the output of the program?
public class WBFoo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
Finally
Compilation fails
An exception is thrown at runtime
The code runs with no output
31. What will be the output of the program?
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
Compilation fails
finished
Exception
Arithmetic Exception
32. What will be the output of the program?
public class WithoutBook
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() {}
}
ACD
AB
AC
BC
33. Which two of the following methods are defined in class Thread?
1. start()
2. wait()
3. notify()
4. run()
5. terminate()
1 and 4
3 and 4
2 and 3
2 and 4
34. Which of the following will directly stop the execution of a Thread?
wait()
notify()
notifyall()
exits synchronized code
35. Which of the following will not directly cause a thread to stop?
notify()
wait()
sleep()
InputStream access
36. Which class or interface defines the wait(), notify(),and notifyAll() methods?
Object
Runnable
Thread
Class
37. public Object wb()
{
Object o = new Float(3.14F);
Object [] oa = new Object[l];
oa[0] = o; /* Line 5 */
o = null; /* Line 6 */
oa[0] = null; /* Line 7 */
return o; /* Line 8 */
}
When is the Float object, created in line 3, eligible for garbage collection?
just after line 7
just after line 5
just after line 6
just after line 8
38. Which of the following would compile without error?
int a = Math.abs(-5);
int b = Math.abs(5.0);
int d = Math.abs(5L);
int c = Math.abs(5.5F);
39. What will be the output of the program?
int i = 1, j = 10;
do
{
if(i++ > --j)
{
continue;
}
} while (i < 5);
System.out.println("i = " + i + "and j = " + j);
i = 5 and j = 6
i = 6 and j = 5
i = 5 and j = 5
i = 6 and j = 6
40. What will be the output of the program?
System.out.println(Math.sqrt(-4D));
NaN
-2
Compile Error
Runtime Exception
41. What will be the output of the program?
class Tree { }
class Pine extends Tree { }
class Oak extends Tree { }
public class Forest1
{
public static void main (String [] args)
{
Tree tree = new Pine();
if( tree instanceof Pine )
System.out.println ("Pine");
else if( tree instanceof Tree )
System.out.println ("Tree");
else if( tree instanceof Oak )
System.out.println ( "Oak" );
else
System.out.println ("Oops ");
}
}
Pine
Tree
Forest
Oops
42. The Java interpreter is used for the execution of the source code.
True
False
43. On successful compilation a file with the class extension is created.
True
False
44. The Java source code can be created in a Notepad editor.
True
False
45. The Java Program is enclosed in a class definition.
True
False
46. Java supports multidimensional arrays.
True
False
47. An array of arrays can be created.
True
False
48. When a string literal is used in the program, Java automatically creates instances of the string class.
True
False
49. Which of the following are primitive types?
byte
String
Integer
Float
50. public class CoreJavaOnlineTest1 {
public static void main(String[] args) {
String s1 = "withoutbook";
String s2 = s1;
s1 = null;
System.out.println("s1:"+s1+" s2:"+s2);
}
}
What is the output?
s1:null s2:withoutbook
s1:null s2:null
Exception
None of the above
51. Palindrome nos are which from the below:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33
0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21
0, 5, 10, 15, 20, 25
0, 1, 1, 2, 3, 5, 8, 13, 21
52. package testpackage;
class Test {
public static void main (String[] args){
try{
System.out.println("I am withoutbook.");
}catch(Exception e){
e.printStackTrace();
}catch(NullPointerException e){
e.printStackTrace();
}
}
}
What is the output?
Exception as java.lang.NullPointerException has already been caught
Compile time exception
Runtime exception
I am withoutbook.
53. Switch statement can hold which type from options:
int, short, char, enum
int, short, long
int, short, char, long
int, char, boolean
54. Which are correct input-output options :
public class Test{
public static void main(String args[])
{
public int test(char a) {
if (a <= 'N') {
if (a == 'E')
return 2;
return 1;
} else if (a == 'S')
return 3;
else if (a == 'W')
return 4;
return 0; }
}
}
a='X' output=0
a='D' output=0
Compile error.
None of the above.
55. interface Test{
void f1(); // 1
public void f2(); // 2
protected void f3(); // 3
private void f4(); // 4
}
which lines generate compile time errors?
compiletime error at lines 3,4
compiletime error at line 1
compiletime error at line 3
compiletime error at lines 1,2,3,4
56. class Test
{
static class C
{
static int i1;
}
public static void main(String a[])
{
System.out.println(Test.C.i1);
}
}
What is the result of attempting to compile and run the program?
prints 0
Compile time error
Runtime exception
None of the above
57. Each element must be unique
Duplicate elements must not replace old elements.
Elements are not key/value pairs.
Accessing an element can be almost as fast as performing a similar operation on an array.
Which of these classes provide the specified features?
HashSet
HashMap
TreeMap
LinkedList
58. class Test1
{
static interface I
{
static class Test2
{
}
}
public static void main(String a[])
{
Test1.I.Test2 ob1=new Test1.I.Test2();
System.out.println("object created");
}
}
What is the result of attempting to compile and run the program?
prints object created
Runtime Exception
Compile time error
None of the above
59. What is byte code in the context of Java?
The type of code generated by a Java compiler.
The type of code generated by a Java Virtual Machine.
It is another name for a Java source file.
It is the code written within the instance methods of a class.
60. What is the output of the following code:
package testpackage;
public class Test{
public static void main(String args[]){
int sum = 0, p = 1;
for (int count = 1; count <= 50; count++)
{
sum += p;
p *= 2;
}
System.out.println(sum);
}
}
-1
1125899906842623
ArithmeticException
IllegalArgumentException
61. What gets printed when the following code is compiled and run with the following command -
java test 2
Select the one correct answer.
public class test {
public static void main(String args[]) {
Integer intObj=Integer.valueOf(args[args.length-1]);
int i = intObj.intValue();
if(args.length > 1)
System.out.println(i);
if(args.length > 0)
System.out.println(i - 1);
else
System.out.println(i - 2);
}
}
1
0
test -1
test
62. Is the following statement true or false. The constructor of a class must not have a return type.
TRUE
FALSE
63. Which of the following is true. Select the correct answer.
A class that is abstract may not be instantiated.
The final keyword indicates that the body of a method is to be found elsewhere. The code is written in non-Java language, typically in C/C++.
A method defined as private indicates that it is accessible to all other classes in the same package.
A static variable indicates there are multiple copies of that variable.
64. What all gets printed when the following gets compiled and run. Select the correct answer.
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
0
3
4
0
1
2
0
2
3
1
2
3
65. What all gets printed when the following gets compiled and run. Select the correct answer.
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i == j)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
3
4
0
1
1
2
2
3
66. What all gets printed when the following gets compiled and run. Select the correct answer.
public class test {
public static void main(String args[]) {
String s1 = "abc";
String s2 = "abc";
if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
1
3
1
2
2
3
3
1
67. What gets printed when the following code is compiled and run. Select the one correct answer.
public class test {
public static void main(String args[]) {
int i = 1;
do {
i--;
} while (i > 2);
System.out.println(i);
}
}
0
1
2
-1
68. Which of these is a legal definition of a method named m assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select the one correct answer.
void m() throws IOException{}
void m() throw IOException{}
void m() {} throws IOException
m() throws IOException{}
69. If a base class has a method defined as
void method() { }
Which of the following are legal prototypes in a derived class of this class. Select the correct answer.
void method() { }
int method() { return 0;}
private void method() { }
70. Is the following statement true or false. As the toString method is defined in the Object class, System.out.println can be used to print any object.
True
False
71. What is the result of compiling and running the following program.
public class test {
public static void main(String args[]) {
String str1="abc";
String str2="def";
String str3=str1.concat(str2);
str1.concat(str2);
System.out.println(str1);
}
}
abc
def
abcabc
abcdef
72. What is the process by which one object acquires the properties of another object?
Polymorphism
Inheritence
73. What is a highly optimized set of instructions designed to be executed by the Java run-time system?
View Code
Byte Code
74. What does J2SE mean?
Java 2 Platform Independent Standard Edition
Java 2 Platform Standard Edition
75. Java does not supports multithreaded programming.
TRUE
FALSE
76. The Separator, Comma is Used to separate package names from subpackages and classes
TRUE
FALSE
77. Objects are sometimes referred to as __ of a class
Interface
Instance
78. When Java source code is compiled, each individual class is put into its own output file named after the class and using the __ extension
.java
.class
79. Can an Interface be final?
Yes
No
80. Can we define private and protected modifiers for variables in interfaces?
Yes
No
81. Can a Byte object be cast to a double value?
Yes
No
82. A class can be converted to a thread by implementing the interface __
Thread
Runnable
83. What is the output of following piece of code ?
int x = 2;
switch (x) {
case 1:System.out.println("1″);
case 2:
case 3:System.out.println("3″);
case 4:
case 5:System.out.println("5″);
}
1, 3 and 5
3 and 5
84. What will be the result of attempting to compile and run this.
class Base{}
class Derived extends Base{}
public class Test {
public static void main(String[] args){
Derived d = (Derived) new Base();
}
}
Compiles and runs without error.
Runtime error
85. What is the value of "d" after this line of code has been executed?
double d = Math.round ( 2.5 + Math.random( ));
2
3
4
4.5
86. You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?
java.util.Map
java.util.Set
java.util.List
java.util.Collection
87. Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence?
java.util.ArrayList
java.util.LinkedHashMap
java.util.HashMap
java.util.TreeMap
88. What is the name of the method used to start a thread execution?
init();
start();
run();
resume();
89. Which method registers a thread in a thread scheduler?
run();
start();
construct();
register();
90. Which one of these lists contains only Java programming language keywords?
class, if, void, long, Int, continue
goto, instanceof, native, finally, default, throws
try, virtual, throw, final, volatile, transient
strictfp, constant, super, implements, do
91. Which is true about a method-local inner class?
It must be marked final.
It can be marked abstract.
It can be marked static.
It can be marked public.
92. Which statement is true about a static nested class?
You must have a reference to an instance of the enclosing class in order to instantiate it.
It does not have access to nonstatic members of the enclosing class.
It must extend the enclosing class.
It's variables and methods must be static.
93. Given
class Base{
Base(){
System.out.print("Base");
}
}
public class Alpha extends Base{
public static void main(String[] args){
new Alpha();
new Base();
}
}
What is the result?
Base
BaseBase
Compilation fails
The code runs with no output
94. Given:
class A {
A( ) {
}
}
class B extends A {
}
Which statement is true?
Class B'S constructor is public.
Class B'S constructor has no arguments.
Class B'S constructor includes a call to this( ).
95. Which cause a compiler error?
int[ ] scores = {3, 5, 7};
int [ ][ ] scores = {2,7,6}, {9,3,45};
String cats[ ] = {"Fluffy", "Spot", "Zeus"};
96. You want to limit access to a method of a public class to members of the same class. Which access accomplishes this objective?
public
private
protected
transient
97. What is an infinite loop?
A loop that functions infinitely well
A loop that runs forever
A loop that never starts
A loop that will never function
98. What is the purpose of this bit of code
void init()
{
...
}
a class that initializes the applet
A required method in an applet
A place to declare variables
Interacting with the user
99. The following is NOT an example of a data type.
int
public
void
double
100. What is the value stored in result after executing the following line in a program?
result = 6/2*3;
1.2
9
1
0
101. What will be the output of the program?
public class WithoutBook
{
public static void main(String args[])
{
try
{
System.out.print("Hello world ");
}
finally
{
System.out.println("Finally executing ");
}
}
}
Hello world.
Hello world Finally executing
Nothing. The program will not compile because no catch clauses are specified.
Nothing. The program will not compile because no exceptions are specified.
102. What is the name of the method used to start a thread execution?
init()
start()
run()
resume()
103. Which two are valid constructors for Thread?
1. Thread(Runnable r, String name)
2. Thread()
3. Thread(int priority)
4. Thread(Runnable r, ThreadGroup g)
5. Thread(Runnable r, int priority)
2 and 5
1 and 2
2 and 4
1 and 3
104. Which three are methods of the Object class?
1. notify();
2. notifyAll();
3. isInterrupted();
4. synchronized();
5. interrupt();
6. wait(long msecs);
7. sleep(long msecs);
8. yield();
2,3,4
1,2,6
2,4,5
1,2,4
105. Which three guarantee that a thread will leave the running state?
1. yield()
2. wait()
3. notify()
4. notifyAll()
5. sleep(1000)
6. aLiveThread.join()
7. Thread.killThread()
4, 5 and 7
2, 5 and 6
3, 4 and 7
1, 2 and 4
106. Which method registers a thread in a thread scheduler?
run()
start()
construct()
register()
107. public class MyRunnable implements Runnable
{
public void run()
{
// some code here
}
}
which of these will create and start this thread?
new MyRunnable().start();
new Thread(new MyRunnable()).start();
new Thread(MyRunnable).run();
new Runnable(MyRunnable).start();
108. class WithoutBook
{
private Demo d;
void start()
{
d = new Demo();
this.takeDemo(d); /* Line 7 */
} /* Line 8 */
void takeDemo(Demo demo)
{
demo = null;
demo = new Demo();
}
}
When is the Demo object eligible for garbage collection?
After the start() method completes
When the instance running this code is made eligible for garbage collection.
After line 7
After line 8
109. public class WithoutBook
{
public static void main(String [] args)
{
WithoutBook x = new WithoutBook();
WithoutBook x2 = m1(x); /* Line 6 */
WithoutBook x4 = new WithoutBook();
x2 = x4; /* Line 8 */
doComplexStuff();
}
static WithoutBook m1(WithoutBook mx)
{
mx = new WithoutBook();
return mx;
}
}
After line 8 runs. how many objects are eligible for garbage collection?
0
1
2
3
110. What allows the programmer to destroy an object x?
Runtime.getRuntime().gc()
Only the garbage collection system can destroy an object.
x.finalize()
x.delete()
111. What is the value of "d" after this line of code has been executed?
double d = Math.round ( 2.5 + Math.random( ));
2
3
4
2.5
112. Which of the following are valid calls to Math.max?
Math.max(1,4)
Math.max(2.3, 5)
Math.max(1, 3, 5, 7)
Math.max(-1.5, -2.8f)
1, 2 and 3
1, 2 and 4
2, 3 and 4
2, 3 and 4
113. What will be the output of the program?
int i = (int) Math.random();
i = 1
i = 0
Statement causes a compile error
value of i is undetermined
114. What will be the output of the program?
class A
{
public A(int x){}
}
class B extends A { }
public class test
{
public static void main (String args [])
{
A a = new B();
System.out.println("complete");
}
}
Prints "complete"
Compile Error
It compiles and runs printing nothing
Compiles but fails at runtime
115. What will be the output of the program?
public class StringRef
{
public static void main(String [] args)
{
String s1 = "abc";
String s2 = "def";
String s3 = s2;
s2 = "ghi";
System.out.println(s1 + s2 + s3);
}
}
abcghighi
abcghidef
abcdefdef
abcdefghi
116. What will be the output of the program?
public class WithoutBook
{
public static void stringReplace (String text)
{
text = text.replace ('j' , 'c');
}
public static void bufferReplace (StringBuffer text)
{
text = text.append ("c");
}
public static void main (String args[])
{
String textString = new String ("java");
StringBuffer textBuffer = new StringBuffer ("java");
stringReplace(textString);
bufferReplace(textBuffer);
System.out.println (textString + textBuffer);
}
}
java
javajavac
Compile error
javac
117. What will be the output of the program?
String s = "hello";
Object o = s;
if( o.equals(s) )
{
System.out.println("A");
}
else
{
System.out.println("B");
}
if( s.equals(o) )
{
System.out.println("C");
}
else
{
System.out.println("D");
}
1. A
2. B
3. C
4. D
2 and 4
1 and 3
3 and 4
1 and 2
118. What will be the output of the program?
public class BoolTest
{
public static void main(String [] args)
{
Boolean b1 = new Boolean("false");
boolean b2;
b2 = b1.booleanValue();
if (!b2)
{
b2 = true;
System.out.print("x ");
}
if (b1 & b2)
{
System.out.print("y ");
}
System.out.println("z");
}
}
z
x z
y z
Compilation fails.
119. Converting of primitive types to objects can be explicitly.
True
False
120. public class CoreJavaOnlineTest1 {
public void main(String[] args) {
System.out.println("WithoutBook Test Example.");
}
}
What is the output?
WithoutBook Test Example.
java.lang.NoSuchMethodError
No output
No Exception
121. public class CoreJavaOnlineTest1 {
public static void main(String[] args) {
String s = "raidua";
System.out.println(s.lastIndexOf('a', 2));
}
}
What is the output?
-1
1
2
5
122. A signed data type has an equal number of non-zero positive and negative values available.
True
False
123. Suppose Class B extends Class A.
And all classes extends Object.
So here Class B extending Class A and Object both. So is it multiple inheritance?
True
False
124. What all gets printed when the following code is compiled and run? Select the three correct answers.
public class xyz {
public static void main(String args[]) {
for(int i = 0; i < 2; i++) {
for(int j = 2; j>= 0; j--) {
if(i == j) break;
System.out.println("i=" + i + " j="+j);
}
}
}
}
i=0 j=0
i=0 j=1
i=0 j=2
i=0 j=1
i=0 j=2
i=1 j=2
i=2 j=0
i=2 j=1
i=2 j=2
i=1 j=0
i=1 j=1
i=1 j=2
125. What is the result of evaluating the expression 14 ^ 23. Select the one correct answer.
37
25
6
31
126. Which of the following are true. Select the one correct answer.
~ operator is the bit-wise XOR operator.
&& operator is used for short-circuited logical AND.
| operator is used to perform bitwise OR and also short-circuited logical OR.
The unsigned right shift operator in Java is >>.
127. What all gets printed when the following gets compiled and run. Select the correct answer.
public class test {
public static void main(String args[]) {
String s1 = "abc";
String s2 = new String("abc");
if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
1
2
2
3
1
3
2
1
128. String s = new String("xyz");
Assuming the above declaration, which of the following statements would compile. Select the one correct answer.
s = s >> 2;
s = s + s;
int i = s[0];
s = 2 * s;
129. In which all cases does an exception gets generated. Select the two correct answers.
int i = 0, j = 1;
if((i == 0) || (j/i == 1))
if((i == 0) | (j/i == 1))
if((i != 0) && (j/i == 1))
None of the above
130. Which of the following statements are true. Select the correct answer.
The wait method defined in the Thread class, can be used to convert a thread from Running state to Waiting state.
The wait(), notify(), and notifyAll() methods must be executed in synchronized code.
The Thread class is an abstract class.
The notify() and notifyAll() methods can not be used to signal and move waiting threads to ready-to-run state.
131. Which of these classes implement the Collection interface SortedMap. Select the one correct answer.
HashMap
TreeMap
HashTable
HashSet
132. Which of the following are true about interfaces. Select the correct answer.
Methods declared in interfaces are implicitly private.
Variables declared in interfaces are implicitly public, static, and final.
The keyword implements indicate that an interface inherits from another.
An interface can not extend any number of interfaces.
133. What is the return type of method round(double d) defined in Math class?
int
long
float
double
134. Which of the class defined in java.io and used for file-handling is abstract. Select the correct answer.
PrintStream
Reader
FileInputStream
FileWriter
135. Select the one correct answer. Which method defined in Integer class can be used to convert an Integer object to primitive int type.
valueOf
intValue
getInt
getInteger
136. Name the return type of method hashCode() defined in Object class, which is used to get the unique hash value of an Object.
short
int
long
double
137. Name the keyword that makes a variable belong to a class, rather than being defined for each instance of the class. Select the one correct answer.
final
static
volatile
native
138. Java support RMI. What does this
RMI
stands for?
Redundant Memory Invocation
Random Memory Invocation
Remote Method Invocation
139. public class Wbfile
{
public static void main (String[] args)
{
String a = args[1];
String b = args[2];
String c = args[3];
System.out.println("Arg is " + c);
}
}
Select how you would start the program to cause it to print: Arg is 2
java Wbfile 222
java Wbfile 1 2 2 3 4
java Wbfile 1 3 2 2
java Wbfile 0 1 2 3
140. Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?
java.lang.String
java.lang.Double
java.lang.StringBuffer
java.lang.Character
141. You need to store elements in a collection that guarantees that no duplicates are stored. Which one of the following interfaces provide that capability?
Java.util.Collection
Java.util.List
Java.util.Map
None of the above
142. What is the numerical range of char?
-256 to 255
0 to 32767
0 to 65535
-32768 to 32767
143. Which cannot directly cause a thread to stop executing?
Calling the SetPriority() method on a Thread object.
Calling the wait() method on an object.
Calling notify() method on an object.
Calling read() method on an InputStream object.
144. Which method must be defined by a class implementing the java.lang.Runnable interface?
void run()
public void start()
public void run()
void run(int priority)
145. Which is a reserved word in the Java programming language?
subclasses
reference
native
method
146. Which one is a valid declaration of a boolean?
boolean b = 0;
boolean b = 'false';
boolean b = false;
boolean b = Boolean.false();
147. In which case does the compiler supply a default constructor for class A?
class A {
public A( ) {
}
}
class A {
public A(int x) {
}
}
class Z {
}
class A extends Z {
void A( ) {
}
}
148. Given: public class Test { }
What is the prototype of the default constructor?
private Test( )
Test(void)
public Test( )
public Test(void)
149. You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?
public
private
protected
transient
150. Which one create an instance of an array?
float fa = new float[20];
char[ ] ca = "Some String";
Object oa = new float[20];
Answered along with the question with tick and cross mark.